﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace DAL
{
    public class AddressDAL
    {
        //删除
        public static bool deleteDAL(int AddressID)
        {
            string sql=string.Format("delete from tb_Address where AddressID={0}",AddressID);
            return DBHelper.ExecuteNonQuery(sql);
        }
        //增加
        public static bool addAddressDAL(Address address)
        {
            string sql = string.Format("insert into tb_Address(Name,UserID,Phone,AddressU) values ('{0}',{1},'{2}','{3}')",address.Name,address.UserID,address.Phone,address.AddressU);
            return DBHelper.ExecuteNonQuery(sql);
        }
        //根据用户ID进行查询
        public static List<Address> getByUserID(int UserID)
        {
            string sql=string.Format("select * from tb_Address where UserID='{0}'",UserID);
            List<Address> list = new List<Address>();
            SqlDataReader dr=DBHelper.GetDataReader(sql);
            while (dr.Read())
            {
                Address address = new Address();
                address.AddressID = dr.GetInt32(0);
                address.Name = dr.GetString(1);
                address.UserID = dr.GetInt32(2);
                address.Phone = dr.GetString(3);
                address.AddressU=dr.GetString(4);
                address.Moren = dr.GetInt32(5);
                list.Add(address);
            }
            dr.Close();
            return list;
        }
    }
}
